﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 海漫思考核.BLL;
using 海漫思考核.DAL;

namespace 海漫思考核
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 登录点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_login_Click(object sender, EventArgs e)
        {
            //获取用户在前台输入的值
            User user = new User()
            {
                Uname = text_username.Value,
                Upwd = text_password.Value
            };
            //查询用户是否存在
            if (UserBLL.UserExists(user))
            {
                user = UserBLL.SelectByUname(user.Uname);//获取用户对应的值
                string type;
                string href;
                //判断用户类型和对应网址
                if (user.Utype == "admin")
                {
                    href = "ManageNove.aspx";
                    type = "管理员";
                }
                else
                {
                    href = "NoveList.aspx";
                    type = "用户";
                }
                //将用户保存到session
                Session["User"] = user;
                Response.Write($"<script>alert('{user.Uname + type},登陆成功！');location.href = '{href}';</script>");
            }else
                Response.Write("<script>alert('登陆失败！')</script>");
        }
    }
}